define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'product/index',
                    add_url: 'product/add',
                    edit_url: 'product/edit',
                    del_url: 'product/del',
                    multi_url: 'product/multi',
                    table: 'web_product'
                },
                showExport: false
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh DESC, id desc',
                columns: [
                    [
                        { field: 'state', checkbox: true, },
                        { field: 'id', title: __('Id') },
                        { field: 'cate', title: __('Cate ID'), operate: false },
                        { field: 'store', title: __('Store'), operate: false },
                        { field: 'title', title: __('Title'), operate: 'LIKE' },
                        { field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false },
                        // { field: 'content', title: __('Content'), operate: false },
                        { field: 'weigh', title: __('Weigh'), sortable: true, operate: false },
                        { field: 'is_show', title: __('Is release'), formatter: Table.api.formatter.status, searchList: { 0: __('Is release false'), 1: __('Is release true') }, sortable: true },
                        { field: 'is_classic', title: __('Is classic'), formatter: Table.api.formatter.status, searchList: { 0: __('NOT'), 1: __('Yes') }, sortable: true },
                        { field: 'create_time', title: __('create time'), addclass: 'datetimerange', datetimeFormat: 'YYYY-MM-DD' },
                        {
                            field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            this.api.bindevent();
        },
        edit: function () {
            this.api.bindevent();
        },
        api: {
            data: {
                defaultWeigh: 1
            },
            bindevent: function () {
                var self = this;

                Form.api.bindevent($("form[role=form]"));
                var old = $('#c-content').val();
                $('.btn-reset').click(function () {
                    $('#c-content').summernote('code',old);
                });
                
                //self.changeType($('input[name="row[type]"]:checked').val());
                //$('input[name="row[type]"]').change(function () {
                //    var type = $(this).val();
                //    self.changeType(type);
                //});
            },
            //changeType: function (type) {
            //    if (type == 1) {
            //        $(".type-url").hide();
            //        $(".type-editor").show();
            //    } else {
            //        $(".type-editor").hide();
            //        $(".type-url").show();
            //    }
            //},
        }
    };
    return Controller;
});